// Copyright (c) 2025, qiushike and contributors
// For license information, please see license.txt

frappe.query_reports["Employee Production Wage"] = {
	"filters": [
		{
			fieldname: "employee",
			label: __("Employee"),
            fieldtype: "Link",
			options: "Employee",
			get_query: () => {
				return {
					query: "light_mes.light_mes.report.employee_production_wage.employee_production_wage.employee_query",					
				};
			},
		},
		{
			fieldname:"operation",
			label: __("Operation"),
            fieldtype: "Link",
			options: "Operation"
        },
		{
			fieldname: "from_date",
			label: __("From Date"),
			fieldtype: "Date",
			reqd: 1,
			default: frappe.datetime.get_today(),
		},
		{
			fieldname:"to_date",
			label: __("To Date"),
			fieldtype: "Date"
		},
		{
			fieldname:"workstations",
			label: __("Workstation"),
            fieldtype: "MultiSelectList",
			get_data: function(txt) {
				return frappe.db.get_link_options('Workstation', txt,{
				});
			}		
		},
        {
			"fieldname": "summary_level",
			"label": __("Summary Level"),
			"fieldtype": "Select",
            "default":"Day",
			"options":['Day','Week','Month','Year'],
			"width": "50",						
		}
	],
	onload: function(report) {		
		// set current user default employee			
		frappe.call({
			method: "light_mes.light_mes.report.employee_production_wage.employee_production_wage.get_allowed_employees"
		})
		.then((r)=>{
			let df =frappe.query_report.get_filter("employee");
			if (r && r.length){				
				df.set_value(r[0]);				
			}
			if (r.length && r.length === 1){
				report.page.fields_dict["employee"].df.hidden = 1;
  				report.page.fields_dict["employee"].$wrapper.hide();
			}
		})
	}
};
